//package com.star.spring.ai.controller;
//
//import org.springframework.ai.chat.messages.Message;
//import org.springframework.ai.chat.messages.SystemMessage;
//import org.springframework.ai.chat.messages.UserMessage;
//import org.springframework.ai.chat.prompt.Prompt;
//import org.springframework.ai.embedding.EmbeddingOptionsBuilder;
//import org.springframework.ai.embedding.EmbeddingRequest;
//import org.springframework.ai.embedding.EmbeddingResponse;
//import org.springframework.ai.ollama.OllamaChatModel;
//import org.springframework.ai.ollama.OllamaEmbeddingModel;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.util.StringUtils;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//import reactor.core.publisher.flux;
//
//import java.util.Arrays;
//import java.util.List;
//
//@RestController
//public class OllamaController {
//
//    @Autowired
//    private OllamaChatModel chatModel;
//
//    @Autowired
//    private OllamaEmbeddingModel ollamaEmbeddingModel;
//
//    @GetMapping(value = "/ai/generateStream", produces = "text/html;charset=UTF-8")
//    public flux<String> generateStream(@RequestParam(value = "message", defaultValue = "给我讲一个笑话") String message) {
//        List<Message> messageList = Arrays.asList(new SystemMessage("请全部用简体中文回答"), new UserMessage(message));
//        Prompt prompt = new Prompt(messageList);
//        return chatModel.stream(prompt).map((r) -> r.getResult() != null && r.getResult().getOutput() != null && r.getResult().getOutput().getContent() != null ? r.getResult().getOutput().getContent() : "").filter(StringUtils::hasLength);
//    }
//
//    @GetMapping(value = "/ai/generateEmbedding", produces = "text/html;charset=UTF-8")
//    public String generateEmbedding(@RequestParam(value = "message", defaultValue = "给我讲一个笑话") String message) {
//        EmbeddingRequest request = new EmbeddingRequest(List.of(message), EmbeddingOptionsBuilder.builder().build());
//        EmbeddingResponse embeddingResponse = ollamaEmbeddingModel.call(request);
//        return Arrays.toString(embeddingResponse.getResult().getOutput());
//    }
//
//}
